﻿// df测试.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include "../../df/df.h"
#include "../../df/Thread.h"
#include "../../df/Config.h"
#include "../../df/CodeConvert.h"
#include "../../df/df_net.h"
#include "../../df/AutoPtr.h"
// #include "../../df/cryptology/mbedtls/rsa.h"
// #include "../../df/cryptology/mbedtls/Crypt.h"
#include "../../df/http/Http.h"
#include "../../df/gzip/df_zip.h"
#include "../../df/df_json.h"

using namespace df;
using namespace std;

using namespace df::sdf;
class tc3
{
public:
	long long eee;
	String ppp;
	META_DATA_INIT;
};

META_DATA_MEMBER(tc3, eee);
META_DATA_MEMBER(tc3, ppp);
META_DATA_END(tc3);



class tc2{
public:
	String eee;
	int fff;
	tc3 iii;
	META_DATA_INIT;
};

META_DATA_MEMBER(tc2, eee);
META_DATA_MEMBER(tc2, fff);
META_DATA_MEMBER_COMP(tc2, iii);
META_DATA_END(tc2);


class tc1
{
public:
	String aaa;
	int bbb;
	bool ccc;
	double ddd;
	tc2 ggg;
	tc3 uuu;

	META_DATA_INIT;
};

META_DATA_MEMBER(tc1, aaa);
META_DATA_MEMBER(tc1, bbb);
META_DATA_MEMBER(tc1, ccc);
META_DATA_MEMBER(tc1, ddd);
META_DATA_MEMBER_COMP(tc1, ggg);
META_DATA_MEMBER_COMP(tc1, uuu);
META_DATA_END(tc1);


int AutoPtrTest = 1;


class testPtr{
	DF_PTR_REF_COUNT;

	~testPtr(){
		AutoPtrTest--;
		Cout << tcc_("析构");
	}


};




df::Event eve_;

df::ThreadPool<5> pool_;

int pooCount = 0;

int main(int, _TCHAR*[])
{
	df::Exception::Instal();
	df::Init();
	//setlocale(LC_ALL, "zh");

	{
		
	}

	{

		for (int i = 0; i < 50; i++)
		{
			df::Thread::Start([&] {
				for (int i = 0; i < 1000; i++)
				{
					pool_.Run([=] {
						df::AtomInc(&pooCount);
					});
				}
			});
		}
		
		df::Thread::Start([&] {
			df::ThreadSleep(6000);
			DF_TEST(pooCount == 50000);
		});

	}
	{
		CC ccn = tcc_("1234");
		DF_TEST(ccn.ToInt() == 1234);

		ccn = tcc_("1234.5");
		DF_TEST(ccn.ToDouble() == 1234.5);

	}

	{

		std::string ff = "可以siodj92u029jf2j3oih-0i!@#$%^&*()`~!@#$%^&*(PL>:{}\"{_ + {:><>}}";
		std::string to;

		HttpParse::Encode(ff, to);
		string ssss = to;
		DF_TEST(to == "%BF%C9%D2%D4siodj92u029jf2j3oih-0i%21%40%23%24%25%5E%26*()%60~%21%40%23%24%25%5E%26*(PL%3E%3A%7B%7D%22%7B_%20%2B%20%7B%3A%3E%3C%3E%7D%7D");
// 		std::string urlen;
// 		CCa skip = "!'()*-._~";
// 		for (int i = 0; i < 256; i++)
// 		{
// 			char c = (char)i;
// 			if (c >= '0' && c <= '9'
// 				|| c >= 'a' && c <= 'z'
// 				|| c >= 'A' && c <= 'Z'
// 				|| skip.Find(c)>0
// 				)
// 			{
// 				urlen << "CCa(\"" << c << "\", 1),\r\n";
// 			}
// 			else
// 				urlen << "CCa(\"%" << CharSelect<char>::GetTable()[(i >> 4)]
// 				<< CharSelect<char>::GetTable()[(i & 0xF)]
// 				<< "\", 3),\r\n";
// 		}
// 
// 		Cout << urlen;
	}
	{
		CC ttFn = tcc_("/sasd/asdsa/terer/sdff/aaa.txt");
		auto tfres = df::File::GetFileName(ttFn);
		DF_TEST(tfres == tcc_("aaa.txt"));

		CC ttFn2 = tcc_("aaa.txt");
		DF_TEST(df::File::GetFileName(ttFn2) == tcc_("aaa.txt"));
	}
	{
#ifdef DF_ENABLE_HTTP_GZIP
		string compS = "111111111111111111aosjaowienf2309u293r2joi2jofiewf092j3oihugug72309u923ep2o3jrpo234jr09ufg09rhejoidfjvdf09vjdf9jbdh23hrhf8w9ef";
		string compS2;
		string compS3;
		string compS4;
		df::Err errI;
		compS2.resize(compS.size() * 2);
		compS3.resize(compS.size() * 2);
		df::Compress comp;
		comp.Init(true, errI);

		DF_TEST(errI == false);
		df::UnCompress uncomp;
		uncomp.Init(errI);
		DF_TEST(errI == false);
		df::Err err1;
		comp.CompressStart(true, &compS[0], compS.size(), &compS2[0], compS2.capacity()
			, [&](int size){
			df::Err err2;
			bool unRes = uncomp.UnCompressStart(&compS2[0], size, &compS3[0], compS2.capacity()
				, [&](int size2){
				CCa res(&compS3[0], size2);
				compS4 << res;
			}, err2);

			DF_TEST(err2 == false);

		}, err1);
		DF_TEST(err1 == false);
		DF_TEST(compS4 == compS);
#endif
	}
	{
		std::string rrrrs;
		rrrrs.resize(10);

		rrrrs[0] = 23;
		rrrrs[2] = 0;
		rrrrs[3] = 1;
		rrrrs[4] = 254;
		rrrrs[5] = 255;

		rrrrs.resize(100);


		// 		std::unordered_map<string, string> m1;
		// 		std::unordered_map<string, string> m2;
		// 		vector<string> vs;
		// 		string sstt;
		// 		for (int i = 0; i < 10000; i++)
		// 		{
		// 			sstt << 'a';
		// 			vs.push_back(sstt);
		// 		}
		// 
		// 		int i = 0;
		// 
		// 		i = 0;
		// 		DF_TIME_CLOCK_MSG("string", 10000, {
		// 			m1[std::string(vs[i].c_str(), vs[i].length())] .assign(vs[i].c_str(), vs[i].length());
		// 			i++;
		// 		});
		// 
		// 		i = 0;
		// 		DF_TIME_CLOCK_MSG("cc", 10000, {
		// 
		// 			m2[vs[i]] = vs[i];
		// 			i++;
		// 		});
		// 
		// 		i = 0;
		// 		DF_TIME_CLOCK_MSG("cc", 10000, {
		// 			sstt.clear();
		// 			sstt << m2[std::string(vs[i].c_str(), vs[i].length())];
		// 			i++;
		// 		});
		// 
		// 
		// 		i = 0;
		// 		DF_TIME_CLOCK_MSG("find string", 10000, {
		// 			sstt.clear();
		// 			m2.find(vs[i]);
		// 			i++;
		// 		});
		// 
		// 		i = 0;
		// 		DF_TIME_CLOCK_MSG("find string c_str", 10000, {
		// 			sstt.clear();
		// 			m2.find(vs[30].c_str());
		// 			i++;
		// 		});
		// 
		// 		i = 0;
		// 		DF_TIME_CLOCK_MSG("find cc", 10000, {
		// 			sstt.clear();
		// 			m2.find("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
		// 			i++;
		// 		});
		// 
		// 
		// 		Cout << tcc_("m1:") << m1.size() << tcc_("\n");
		// 		Cout << tcc_("m2:") << m2.size() << tcc_("\n");
	}
	{
		string ss = "ssssssssssssssss";
		string ss2 = std::move(ss);

		ss << "zzzz";
		Cout << "ss:" << ss << "size:" << ss.size();
	}
	{
		Http ht;
		std::string hoos;
		std::string paras;
		uint16_t port;


		hoos.clear();
		paras.clear();
		auto res = HttpParse::ParseHttpURL("http://translate.google.cn", hoos, port, paras);
		DF_TEST(hoos == "translate.google.cn");
		DF_TEST(port == 80);
		DF_TEST(res == HttpType::typeHttp);
		DF_TEST(paras == "");

		hoos.clear();
		paras.clear();
		res = HttpParse::ParseHttpURL("http://translate.google.cn/", hoos, port, paras);
		DF_TEST(hoos == "translate.google.cn");
		DF_TEST(port == 80);
		DF_TEST(res == HttpType::typeHttp);
		DF_TEST(paras == "/");

		hoos.clear();
		paras.clear();
		res = HttpParse::ParseHttpURL("http://translate.google.cn:8888/", hoos, port, paras);
		DF_TEST(hoos == "translate.google.cn");
		DF_TEST(port == 8888);
		DF_TEST(res == HttpType::typeHttp);
		DF_TEST(paras == "/");


		hoos.clear();
		paras.clear();
		res = HttpParse::ParseHttpURL("http://translate.google.cn/#zh-CN/en/%E5%B0%8F%E5%86%99", hoos, port, paras);
		DF_TEST(hoos == "translate.google.cn");
		DF_TEST(port == 80);
		DF_TEST(res == HttpType::typeHttp);
		DF_TEST(paras == "/#zh-CN/en/%E5%B0%8F%E5%86%99");


		hoos.clear();
		res = HttpParse::ParseHttpURL("https://translate.google.cn/#zh-CN/en/%E5%B0%8F%E5%86%99", hoos, port, paras);
		DF_TEST(hoos == "translate.google.cn");
		DF_TEST(port == 80);
		DF_TEST(res == HttpType::typeHttps);

		hoos.clear();
		res = HttpParse::ParseHttpURL("translate.google.cn/#zh-CN/en/%E5%B0%8F%E5%86%99", hoos, port, paras);
		DF_TEST(hoos == "translate.google.cn");
		DF_TEST(port == 80);
		DF_TEST(res == HttpType::typeHttp);

		hoos.clear();
		res = HttpParse::ParseHttpURL("translate.google.cn:80/#zh-CN/en/%E5%B0%8F%E5%86%99", hoos, port, paras);
		DF_TEST(hoos == "translate.google.cn");
		DF_TEST(port == 80);
		DF_TEST(res == HttpType::typeHttp);

		hoos.clear();
		res = HttpParse::ParseHttpURL("translate.google.cn:1122/#zh-CN/en/%E5%B0%8F%E5%86%99", hoos, port, paras);
		DF_TEST(hoos == "translate.google.cn");
		DF_TEST(port == 1122);
		DF_TEST(res == HttpType::typeHttp);

		hoos.clear();
		res = HttpParse::ParseHttpURL("https://translate.google.cn:1122/#zh-CN/en/%E5%B0%8F%E5%86%99", hoos, port, paras);
		DF_TEST(hoos == "translate.google.cn");
		DF_TEST(port == 1122);
		DF_TEST(res == HttpType::typeHttps);


		string head = "HTTP/1.1 200 OK\r\nX-Powered-By: Express\r\nContent-Type: application / json; charset = utf - 8\r\nContent-Length: 40\r\n"
			"Date: Thu, 05 Nov 2015 01 : 11 : 05 GMT\r\n"
			"Connection: keep - alive\r\n\r\n"
			"{ \"code\":200, \"msg\" : \"access\", \"status\" : \"1\" }";
		auto resS = HttpParse::getHttpHeadSize(head.c_str(), head.length());
		head.resize(resS);
		DF_TEST(resS == 182);

		HttpHead hh;
		HttpParse::HeadStrToMap(&head[0], resS, hh);
		DF_TEST(hh.GetMap()[HTTP_keyMethod] == "HTTP/1.1 200 OK");

		DF_TEST(hh.GetMap()[HTTP_keyX_Powered_By] == "Express");
		DF_TEST(hh.GetMap()[HTTP_keyContentType] == "application / json; charset = utf - 8");
		DF_TEST(hh.GetMap()[HTTP_keyContentLength] == "40");
		DF_TEST(hh.GetMap()[HTTP_keyDate] == "Thu, 05 Nov 2015 01 : 11 : 05 GMT");
		DF_TEST(hh.GetMap()[HTTP_keyConnection] == "keep - alive");


		


		hh.Get("222222");
		 
	}
	{
		df::Thread::Start([=]{
			 df::Http ht;
			// 			string resp;
			// 			ht.ConnectURL("119.90.51.126:8080");
			// 
			// 			HttpHead he;
			// 
			// 			he.Set(HTTP_keyMethod, "GET /version/check?version=1.0&os=win HTTP/1.1");
			// 			he.Set(HTTP_keyAccept, "*/*");
			// 
			// 			ht.SendHead(he);
			// 			ht.RecvHead();
			// 			ht.RecvContent([&](char * buf, int len){
			// 				resp << CCa(buf, len);
			// 			});
			// 
			// 			ht.SendHead(he);
			// 			ht.RecvHead();
			// 			ht.RecvContent([&](char * buf, int len)->bool{
			// 				resp << CCa(buf, len);
			// 				return true;
			// 			});
			// 
			// 			ht.GetToString("119.90.51.126:8080/version/check?version=1.0&os=android", he, resp);
			// 
			// 			string ppRes;
			// 			ht.PostToString("119.90.51.126:8080/version/check?version=1.0&os=android", he, "1234", ppRes);
			// 
			// 			ht.CLose();

			Err err;
			HttpHead bai;

			std::string headRes;
			df::json::ObjToJson(ht.GetRecvHead().GetMap(), headRes);

			int allSIze = 0;
			bai.SetKeepAlive();
			bai.SetAcceptAll();
			ht.Get("http://static.oschina.net/uploads/space/2015/1106/182721_yfxd_2306979.jpg"
				, bai, [&](char * buf, int size){

				allSIze += size;
			}, err);
			DF_TEST(err == false);
			DF_TEST(allSIze == 20762);

			string oscRes;
			HttpHead hed;
			hed.SetKeepAlive();
			hed.SetAcceptAll();
			hed.SetAcceptGzip();
			ht.GetToString("http://www.oschina.net/", hed, oscRes, err);
			// 			df::File fi;
			// 			fi.Open("osc.txt");
			// 			fi.Write(oscRes);
			DF_TEST(ht.GetRecvHead().GetHttpCode() == 200);
			DF_TEST(ht.GetRecvHead().GetHttpMsg() == "OK");
			DF_TEST(oscRes.size() > 10);
			DF_TEST(err == false);


			ht.PostFile("http://www.oschina.net/", hed
				, std::pair<CCa, CCa>{ "file", "E:/log.txt" }
			, std::array<std::pair<CCa, CCa>, 0>{}, oscRes
				, [&](int64_t s1, int64_t s2){

			});



// 			bai.SetKeepAlive();
// 
// 			ht.Get("http://127.0.0.1:3000/"
// 				, bai, [&](char * buf, int size){
// 
// 				allSIze += size;
// 			}, err);
// 			df::ThreadSleep(6 * 1000);
// 
// 			bai.SetKeepAlive();
// 
// 			ht.Get("http://127.0.0.1:3000/"
// 				, bai, [&](char * buf, int size){
// 
// 				allSIze += size;
// 			}, err);
// 
// 			DF_TEST(err==false);
		});
	}
	{
		// 		string ssn;
		// 		auto ccc = df::GetCharTable();
		// 		int i = 0;
		// 		for (; i < 65; i++)
		// 		{
		// 			ssn << i << ", ";
		// 		}
		// 		ssn << "\r\n";
		// 		for (; i < 65 + 26; i++)
		// 		{
		// 			ssn <<"'"<< char(i + 32) << "', ";
		// 		}
		// 		ssn << "\r\n";
		// 		for (; i < 256; i++)
		// 		{
		// 			ssn << i << ", ";
		// 		}
		// 		Cout << ssn;


	}
	{
		int64_t res;
		df::StringHexToDigit(tcc_("14"), res);
		DF_TEST(res == 20);
		df::StringHexToDigit(tcc_("0"), res);
		DF_TEST(res == 0);
		df::StringHexToDigit(tcc_("1"), res);
		DF_TEST(res == 1);
		df::StringHexToDigit(tcc_("2"), res);
		DF_TEST(res == 2);
		df::StringHexToDigit(tcc_("9"), res);
		DF_TEST(res == 9);
		df::StringHexToDigit(tcc_("a"), res);
		DF_TEST(res == 10);
		df::StringHexToDigit(tcc_("A"), res);
		DF_TEST(res == 10);
		df::StringHexToDigit(tcc_("b"), res);
		DF_TEST(res == 11);
		df::StringHexToDigit(tcc_("B"), res);
		DF_TEST(res == 11);
		df::StringHexToDigit(tcc_("f"), res);
		DF_TEST(res == 15);
		df::StringHexToDigit(tcc_("F"), res);
		DF_TEST(res == 15);

		df::StringHexToDigit(tcc_("CD17BA8"), res);
		DF_TEST(res == 215055272);
	}
	{
		string ssstestccc;
		ssstestccc << df::ToLowerCaseTable()['A'];
		ssstestccc << df::ToLowerCaseTable()['B'];
		ssstestccc << df::ToLowerCaseTable()['C'];
		ssstestccc << df::ToLowerCaseTable()['D'];
		ssstestccc << df::ToLowerCaseTable()['Y'];
		ssstestccc << df::ToLowerCaseTable()['X'];
		ssstestccc << df::ToLowerCaseTable()['Z'];

		ssstestccc << df::ToLowerCaseTable()['a'];
		ssstestccc << df::ToLowerCaseTable()['b'];
		ssstestccc << df::ToLowerCaseTable()['c'];
		ssstestccc << df::ToLowerCaseTable()['y'];
		ssstestccc << df::ToLowerCaseTable()['x'];
		ssstestccc << df::ToLowerCaseTable()['z'];

		ssstestccc << df::ToLowerCaseTable()['0'];
		ssstestccc << df::ToLowerCaseTable()['1'];
		ssstestccc << df::ToLowerCaseTable()['9'];

		DF_TEST(ssstestccc == "abcdyxzabcyxz019");

		CC sss = tcc_("SJdjfjfjfffffffff");

		auto res = sss.IsMatch(tcc_("sjd"), 0, true);

		DF_TEST(!res);
		DF_TEST(sss.IsMatch(tcc_("sjd"), 0, false));
	}


	{
		df::Thread::Start([]{
			while (1){
				auto res = eve_.Wait();
				Cout << res << tcc_("eve1 wait ok\n");
			}

		});

		df::Thread::Start([]{
			while (1){
				auto res = eve_.Wait();
				Cout << res << tcc_("eve2 wait ok\n");
			}

		});


		df::ThreadSleep(100);
		eve_.SetAll();
		df::ThreadSleep(100);
		eve_.SetAll();
	}

	{
		// 		df::CryptAES128 a;
		// 
		// 		a.InitByteKey((const unsigned char*)"9ce62c1836d128cf");
		// 		char res[128] = { 0 };
		// 
		// 		df::CCa ss = "efe7b182244ad5edc9e8e12909661315";
		// 		df::CCa::StringToByte(ss, res, sizeof(res));
		// 		a.Decrypt(res, res, ss.length() / 2);
		// 
		// 		DF_TEST(df::CCa("ceshi\v\v\v\v\v\v\v\v\v\v\v") == res);
		// 		mbedtls_rsa_self_test(1);
	}

	{
		df::File ff;
		df::Err err;
		ff.Open(tcc_("fftest.txt"), false, false, false, err);
		DF_TEST(err);
		COUT(err.GetInfo());

		DF_TEST(df::ErrCode::GetCodeMsg(df::ErrCode::FileTooBig) == tcc_("文件过大"));

	}

	{
		CCa sscc = "123456";
		String ss;
		std::string sa = "aaaaaa奖惩";
		std::wstring sw = L"bbbb到付";
		ss << "一个测试" << 123 << L"a test 测试" << sscc;
		ss << L"123";
		ss << sa;
		ss << sw;
		DF_TEST(ss == tcc_("一个测试123a test 测试123456123aaaaaa奖惩bbbb到付"));

		sw << sa;
		DF_TEST(sw == L"bbbb到付aaaaaa奖惩");

	}
	{
		df::CCw testS = L"12345678ͷ͸͹ͺͻͼͽ;Ϳ0380΀΁΂΃΄΅Ά·ΈΉΊ΋Ό΍ΎΏ0390ΐΑΒΓΔ0侰侱侲侳侴侵侶侷侸侹侺侻侼侽侾便4FC0俀俁係促俄俅俆俇俈俉俊俋俌俍俎俏4FD0俐俑俒俓俔俕俖俗俘俙俚俛俜保俞俟4FE0俠信俢俣俤俥俦俧俨俩俪俫俬俭修俯ΕΖΗΘΙΚΛΜΝΞΟ03A0ΠΡ΢ΣΤΥΦΧΨΩΪΫ978ǅ ǆ Ǉ ǈ ǉ Ǌ ǋ ǌ Ǎ ǎ Ǐ9~!@#$%^&*()_+qwertyuioZXCVBNM<>>?,./可耻89可耻789789可耻89可耻od盘弄𪚥3456789可耻od盘弄𪚥3𪚥𪚥𪚥𪚥𪚥𪚥𪚥𪚥𪚥𪚥𪚥𪚥𪚥𪚥𪚥𪚥𪚥𪚥𪚥𪚥𪚥45678789可耻89可耻odod盘弄𪚥3456789可耻od盘弄𪚥3𪚥𪚥𪚥𪚥𪚥𪚥𪚥𪚥𪚥𪚥𪚥𪚥𪚥𪚥𪚥𪚥𪚥𪚥𪚥𪚥𪚥45678789可耻89可耻od盘弄𪚥3456789可𪚥𪚥𪚥𪚥𪚥𪚥𪚥𪚥𪚥𪚥45678789可ሀሁሂሃሄህሆሇለሉሊላሌልሎሏ1210ሐሑሒሓሔሕሖሗመሙሚማሜምሞሟ1220ሠሡሢሣሤሥሦሧረሩሪራሬርሮሯ耻89可ᄳᄴᄵᄶᄷᄸᄹᄺᄻᄼᄽᄾᄿ1140ᅀᅁᅂᅃᅄᅅᅆᅇ耻od盘弄𪚥𪚥𪚥അആഇഈഉഊഋഌ഍എഏ0D10ഐ഑ഒഓഔകഖഗ𪚥𪚥𪚥նշոչպջռսվտ0580րցւփքօֆևֈ։֊֋֌֍֎֏0590֐֑֖֛֚֒֓֔֕֗֘֙֜֝֞֟05A0֢֣֤֥֦֧֪֭֮֠֡֨֩֫֬֯05B0ְֱֲֳִֵֶַָֹֺֻּֽ־ֿ05C0׀ׁׂ׃ׅׄ׆ׇ׈׉𪚥𪚥𪚥𪚥𪚥45678789可耻8ѥѦѧѨѩѪѫѬѭѮѯ0470ѰѱѲѳѴѵѶѷѸѹѺѻѼѽѾѿ0480Ҁҁ҂҃҄҅҆҇҈҉ҊҋҌҍҎҏ0490ҐґҒғҔҕҖҗҘҙҚқҜҝҞҟ04A0ҠҡҢңҤҥҦҧҨҩҪҫҬ9可耻od盘弄𪚥𪚥𪚥𪚥𪚥𪚥𪚥𪚥𪚥𪚥𪚥45678789可耻89可耻od盘弄𪚥𪚥𪚥𪚥𪚥𪚥0⨐⨑⨒⨓⨔90㖐㖑㖒㖓㖔㖕㖖㖗㖘㖙㖚㖛㖜㖝㖞㖟35A0㖠㖡㖢㖣㖤㖥㖦㖧㖨㖩㖪㖫㖬㖭㖮㖯35B0㖰㖱㖲㖳㖴㖵㖶㖷㖸㖹㖺㖻㖼㖽㖾㖿35C0㗀㗁㗂㗃㗄㗅㗆㗇㗈㗉㗊㗋㗌㗍㗎㗏35D0㗐㗑㗒㗓㗔㗕㗖㗗㗘㗙㗚㗛㗜㗝㗞㗟⨕⨖⨗⨘⨙⨚⨛⨜⨝⨞⨟2A20⨠⨡⨢⨣⨤⨥⨦⨧⨨⾐⾑⾒⾓⾔⾕⾖⾗⾘⾙⾚⾛⾜⾝⾞⾟2FA0⾠⾡⾢⾣⾤⾥⾦⾧⾨⾩⾪⾫⾬⾭⾮⾯2FB0⾰⾱⾲⾳⾴⾵⾶⾷⾸⾹ㅠㅡㅢㅣㅤㅥㅦㅧㅨㅩㅪㅫㅬㅭㅮㅯ3170ㅰㅱㅲㅳㅴㅵㅶㅷㅸㅹㅺㅻㅼㅽㅾㅿ⾺⾻⾼⾽⾾⾿2FC0⿀⿁⿂80🚀🚁🚂🚃🚄🚅🚆🚇🚈🚉🚊🚋🚌🚍🚎🚏1F690🚐🚑🚒🚓🚔🚕🚖🚗🚘🚙🚚🚛🚜🚝🚞🚟⿃⿄⿅0뎰뎱뎲뎳뎴뎵뎶0010𐀐𐀑𐀒𐀓𐀔𐀕𐀖𐀗𐀘𐀙𐀚𐀛𐀜𐀝𐀞𐀟10020𐀠𐀡𐀢𐀣𐀤𐀥𐀦𐀧𐀨𐀩𐀪𐀫𐀬𐀭𐀮𐀯뎷뎸뎹뎺뎻뎼뎽뎾뎿B3C0돀돁돂돃도독돆돇돈돉돊돋돌돍돎돏B3D0돐돑돒돓돔돕돖돗돘동돚돛돜돝돞돟⿆⿇⿈⿉⿊⿋⿌⿍⿎⿏⨩⨪⨫⨬⨭⨮⨯𪚥𪚥𪚥𪚥𪚥45678789可耻89可耻od盘弄𪚥耻od盘弄𪚥345678789可耻89可耻od盘弄𪚥3456789可耻od盘弄𪚥345678可耻od盘弄𪚥3456789可耻od盘弄𪚥3456789可耻89可耻od盘弄𪚥3456789可耻od盘弄𪚥3456789可耻od盘弄𪚥345678od盘弄𪚥3456789可耻od盘弄𪚥3456789可耻od盘弄𪚥3456789可耻od盘弄𪚥";


		{
			std::string strt2;
			df::code::UTF16ToUTF8(testS, strt2);
			std::wstring wstrt2;
			df::code::UTF8ToUTF16(strt2, wstrt2);

			DF_TEST(wstrt2 == testS);
		}
		string str;
		str.reserve(4096);
		string str2;
		str2.reserve(4096);


		DF_TIME_CLOCK_MSG("WideToUTF8", 100, {
			df::code::WideToUTF8(testS, str);
		});

		DF_TIME_CLOCK_MSG("UTF16ToUTF8", 100, {
			df::code::UTF16ToUTF8(testS, str2);
		});

		wstring wstr;
		wstring wstr2;

		DF_TIME_CLOCK_MSG("UTF8ToWide", 10, {
			df::code::UTF8ToWide(str, wstr);
		});

		DF_TIME_CLOCK_MSG("UTF8ToUTF16", 10, {
			df::code::UTF8ToUTF16(str, wstr2);
		});




		DF_TEST(wstr == wstr2);

	}

	{
		df::AutoPtr<testPtr> ptr = new testPtr();
		auto ptr2 = ptr;
	}


	DF_TEST(AutoPtrTest == 0);
	Regexp rreegg;
	Regexp reg(tcc_("123*"));
	{
		auto sst = df::code::AnsiToWide("123456789可能abcdefghijklmnopqrstuvw");
		DF_TEST(sst == L"123456789可能abcdefghijklmnopqrstuvw");
		auto sst2 = df::code::WideToUTF8(sst);
		auto sst3 = df::code::UTF8ToWide(sst2);
		DF_TEST(sst3 == L"123456789可能abcdefghijklmnopqrstuvw");
		auto sst4 = df::code::WideToAnsi(sst);
		DF_TEST(sst4 == "123456789可能abcdefghijklmnopqrstuvw");

	}

	for (auto & f : df::EachDir(tcc_("e:/"))){
		COUT(f.name_);
	}


	auto cc = df::DiskInfo::GetTypeInfo()[0];
	Cout << cc;

	String resstr = reg.Search(tcc_("11123456")).get(0);
	Cout << tcc_("ressstr字串:") << resstr << endl;


	DF_TEST(resstr == tcc_("123"));

	try{
		for (auto & res : reg.Search(tcc_("11123411")))
		{
			Cout << "res:" << res.str() << endl;
			for (auto & rr : res){
				auto r2 = rr.str();
				Cout << "r2:" << r2 << endl;
			}
		}

		Regexp pattern(tcc_("( (a) (a|e|i|u|o))+"));
		auto repRes = pattern.ReplaceAll(tcc_("This is a element and this a unique ID."), tt_("an $2"));

		for (auto res : reg.Search(tcc_("111111231111")).getMatch())
		{
			auto r2 = res.str();
			Cout << r2;
		}

	}
	DF_CATCH_ALL;

	{

		String st = _T("as");

		String s1 = st + tcc_("21") + tcc_("ss") + tcc_("123asdawr423fasdf");
		String s2 = tcc_("21") + tcc_("22") + s1;
		String s3 = tcc_("21") + s2;
		CC c = s1;





		if (sizeof(void*) == 8){
			int * ip = (int*)0x000000000000ABCD;
			int16_t aa = 1234;
			st << aa << c << ip;
			DF_TEST(st == tcc_("as1234as21ss123asdawr423fasdf0x000000000000ABCD"));
			uint32_t ua = 1234;
			st << ua;
			DF_TEST(st == tcc_("as1234as21ss123asdawr423fasdf0x000000000000ABCD1234"));

			st += -123.5;
			DF_TEST(st == tcc_("as1234as21ss123asdawr423fasdf0x000000000000ABCD1234-123.5"));
			float td1 = 2.123f;
			st += td1;
			DF_TEST(st == tcc_("as1234as21ss123asdawr423fasdf0x000000000000ABCD1234-123.52.123"));
		}
		else{
			int * ip = (int*)0x0000ABCD;
			int16_t aa = 1234;
			st << aa << c << ip;
			DF_TEST(st == tcc_("as1234as21ss123asdawr423fasdf0x0000ABCD"));
			uint32_t ua = 1234;
			st << ua;
			DF_TEST(st == tcc_("as1234as21ss123asdawr423fasdf0x0000ABCD1234"));

			st += -123.5;
			DF_TEST(st == tcc_("as1234as21ss123asdawr423fasdf0x0000ABCD1234-123.5"));
			float td1 = 2.123f;
			st += td1;
			DF_TEST(st == tcc_("as1234as21ss123asdawr423fasdf0x0000ABCD1234-123.52.123"));
		}


		df::DigitProc<int> sa;
		sa.Set(-123);
		DF_TEST(tcc_("-123") == sa.char_);


		char ss[10];
		df::Sprintf(ss, 10, "123");

	};
	{
		bool sires = false;
		df::StringToDigit(tcc_(" 1234"), sires);
		DF_TEST(sires == true);

		int t2 = 0;
		df::StringToDigit(tcc_(" -1234 "), t2);
		DF_TEST(t2 == -1234);

		unsigned short t3 = 0;
		df::StringToDigit("-1234 ", t3);
		DF_TEST(t3 == 1234);

		double d = 0;
		df::StringToDigit(" -0.25", d);
		DF_TEST(d == -0.25);

	}


	{
		try{
			Throw_df(tt_("asd"));
		}
		DF_CATCH_ALL_EXCEPTION({
			Cout << _T("异常");
		});

		df::File fg;
		fg.Open(df::GetDirCurrent() + tt_("gzip.zip"));




	}

	Cout << df::GetDirCurrent();

	df::Thread::Start([]{
		Cout << tt_("线程");
	});

	df::Thread::Start([]{
		Cout << tt_("线程2");
	});

	df::ThreadSleep(100);

	df::Thread::Start([]{
		Cout << tt_("线程3");
	});

	{
		static int tti = 0;

		df::Thread ttt;

		ttt.Run([&]{
			tti++;
		});


		ttt.Wait();

		DF_TEST(tti == 1);

		ttt.Run([&]{
			tti++;
		});


		ttt.Wait();

		DF_TEST(tti == 2);
	}


	ON_SCOPE_EXIT({
		int a = 1;
		a = 2;
		Cout << a;
	});

	{
		std::map<int, int> mp;

		mp[22222] = 33333;
		mp[1] = 2;
		String rres;
		df::json::ObjToJson(mp, rres);


	}
	{
		try
		{

			tc1 tt1;
			tt1.aaa = tt_("123==456a=aa");
			tt1.bbb = 111222;
			tt1.ccc = false;
			tt1.ddd = 123.123;
			tt1.ggg.eee = tt_("abc=def");
			tt1.ggg.fff = 3214;
			tt1.ggg.iii.eee = 4536457;
			tt1.ggg.iii.ppp = tt_("asdf''gfd';hdt y5 dsdfe''dd''' 'jsdf '''dsdvyj");
			tt1.uuu.eee = 93858032355;
			tt1.uuu.ppp = tt_("kldfjs;4t-0sptj\r\ns;elj/gs43;'s\r\ng';4;sg'54[ypl';r'''");

			String rres;
			df::json::ObjToJson(tt1, rres);
			Cout << rres;
			DF_TEST(rres == "{\"aaa\":\"123==456a=aa\",\"bbb\":111222,\"ccc\":false,\"ddd\":123.123,\"ggg\":{\"eee\":\"abc=def\",\"fff\":3214,\"iii\":{\"eee\":4536457,\"ppp\":\"asdf''gfd';hdt y5 dsdfe''dd''' 'jsdf '''dsdvyj\"}},\"uuu\":{\"eee\":93858032355,\"ppp\":\"kldfjs;4t-0sptj\r\ns;elj/gs43;'s\r\ng';4;sg'54[ypl';r'''\"}}");

			df::Config::Write(df::GetDirCurrent() + tcc_("test2.txt"), tt1);

			tc1 tt2;
			df::Config::Read(df::GetDirCurrent() + tcc_("test2.txt"), tt2);
			DF_TEST(tt2.aaa == tt_("123==456a=aa"));
			DF_TEST(tt2.bbb == 111222);
			DF_TEST(tt2.ccc == false);
			DF_TEST(tt2.ddd == 123.123);
			DF_TEST(tt2.ggg.eee == tt_("abc=def"));
			DF_TEST(tt2.ggg.fff == 3214);
			DF_TEST(tt2.ggg.iii.eee == 4536457);
			DF_TEST(tt2.ggg.iii.ppp == tt_("asdf''gfd';hdt y5 dsdfe''dd''' 'jsdf '''dsdvyj"));
			DF_TEST(tt2.uuu.eee == 93858032355);
			DF_TEST(tt2.uuu.ppp == tt_("kldfjs;4t-0sptj\r\ns;elj/gs43;'s\r\ng';4;sg'54[ypl';r'''"));

			Throw_df("测试");
		}
		DF_CATCH_ALL;
	}

	std::getchar();

	return 0;
}

